using System.Collections.Generic;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Server;

namespace LeastPrivilege.CustomBasicAuthentication.Management
{
    // the proxy talks to the module service
    class CustomBasicAuthenticationModuleProxy : ModuleServiceProxy
    {
        public Dictionary<string, string> GetConfiguration()
        {
            var bag = (PropertyBag)base.Invoke("GetConfiguration");
            var config = new Dictionary<string, string>();
            
            config.Add("realm", bag[1].ToString());
            config.Add("providerName", bag[2].ToString());
            config.Add("cachingEnabled", bag[3].ToString());
            config.Add("cachingDuration", bag[4].ToString());
            config.Add("requireSSL", bag[5].ToString());

            return config;
        }

        public Dictionary<string, string> GetEnabled()
        {
            var bag = (PropertyBag)base.Invoke("GetEnabled");
            var config = new Dictionary<string, string>();

            config.Add("enabled", bag[1].ToString());
            config.Add("isLocked", bag[2].ToString());

            return config;
        }

        public void SetConfiguration(Dictionary<string, string> updatedValues)
        {
            PropertyBag bag = new PropertyBag();
            bag.Add(1, updatedValues["realm"]);
            bag.Add(2, updatedValues["providerName"]);
            bag.Add(3, updatedValues["cachingEnabled"]);
            bag.Add(4, updatedValues["cachingDuration"]);
            bag.Add(5, updatedValues["requireSSL"]);

            base.Invoke("SetConfiguration", new object[] { bag });
        }

        public void SetEnabled(bool enabled)
        {
            base.Invoke("SetEnabled", new object[] { enabled });
        }
    }
}
